<?php
	// Load the Qcodo Development Framework
	require('../includes/prepend.inc.php');

	/**
	 * This is a quick-and-dirty draft QForm object to do Create, Edit, and Delete functionality
	 * of the Project class.  It uses the code-generated
	 * ProjectMetaControl class, which has meta-methods to help with
	 * easily creating/defining controls to modify the fields of a Project columns.
	 *
	 * Any display customizations and presentation-tier logic can be implemented
	 * here by overriding existing or implementing new methods, properties and variables.
	 * 
	 * NOTE: This file is overwritten on any code regenerations.  If you want to make
	 * permanent changes, it is STRONGLY RECOMMENDED to move both project_edit.php AND
	 * project_edit.tpl.php out of this Form Drafts directory.
	 *
	 * @package My Application
	 * @subpackage Drafts
	 */
	class ProjectEditForm extends QForm {
		// Local instance of the ProjectMetaControl
		protected $mctProject;
		protected $ProjectFile;
		protected $lblMessage;
		protected $btnButton;

		// Controls for Project's Data Fields
		protected $lblId;
		protected $lstUser;
		protected $lstCategory;
		protected $lstSubcategory;
		protected $txtTitle;
		protected $txtCategoryId1;
		protected $txtCategoryId2;
		protected $txtCategoryId3;
		protected $txtCategoryId4;
		protected $txtCategoryId5;
		protected $txtCategory;
		protected $txtDescription;
		protected $txtOs;
		protected $txtDb;
		protected $txtBudgetMin;
		protected $txtBudgetMax;
		protected $txtFeatured;
		protected $txtHideBid;
		protected $txtHideSearch;
		protected $txtGoldOnly;
		protected $txtEnable;
		protected $txtSendmail;
		protected $txtTotalBid;
		protected $calTimeLimitDate;
		protected $calPostDate;
		protected $calCancelDate;
		protected $calCloseDate;
		protected $calEndDate;
		protected $txtStatus;
		protected $txtWonUserId;
		protected $txtAverageBid;
		protected $calWonDate;
		protected $calStartDate;
		protected $calLastBidDate;
		protected $lstProjectTypeObject;
		protected $lstBudgetTypeObject;
		protected $lstTotalProjectdayTypeObject;
		protected $chkHideSearchEngine;
		protected $chkAgreementCheck;

		// Other ListBoxes (if applicable) via Unique ReverseReferences and ManyToMany References

		// Other Controls
		protected $btnSave;
		protected $btnDelete;
		protected $btnCancel;

		// Create QForm Event Handlers as Needed

//		protected function Form_Exit() {}
//		protected function Form_Load() {}
//		protected function Form_PreRender() {}

		protected function Form_Run() {
			// Security check for ALLOW_REMOTE_ADMIN
			// To allow access REGARDLESS of ALLOW_REMOTE_ADMIN, simply remove the line below
			QApplication::CheckRemoteAdmin();
		}

		protected function Form_Create() {
			$this->ProjectFile = new QFileAsset($this); 
            $this->ProjectFile->Required = true; 
            
            $this->ProjectFile->TemporaryUploadPath =__ProjectFileUpload__;
            $_SESSION['newProject']['FilePath']=__ProjectFileUpload__;
            $this->ProjectFile->ClickToView=false;
            //$this->ProjectFile->FileAssetType=QFileAssetType::AllowedExtensions ;

            $this->ProjectFile->CssClass = 'file_asset';
            $this->ProjectFile->imgFileIcon->CssClass = 'file_asset_icon';
			
            $this->lblMessage = new QLabel($this);
			$this->lblMessage->Text = 'Click to Upload the File.';
			
			$this->btnButton = new QButton($this);
			$this->btnButton->Text = 'Upload';
			$this->btnButton->AddAction(new QClickEvent(), new QAjaxAction('btnButton_Click'));
			$this->btnButton->CausesValidation = false;
			
			// Use the CreateFromPathInfo shortcut (this can also be done manually using the ProjectMetaControl constructor)
			// MAKE SURE we specify "$this" as the MetaControl's (and thus all subsequent controls') parent
			$this->mctProject = ProjectMetaControl::CreateFromPathInfo($this);

			// Call MetaControl's methods to create qcontrols based on Project's data fields
			$this->lblId = $this->mctProject->lblId_Create();
			$this->lstUser = $this->mctProject->lstUser_Create();
			$this->lstCategory = $this->mctProject->lstCategory_Create();
			$this->lstSubcategory = $this->mctProject->lstSubcategory_Create();
			$this->txtTitle = $this->mctProject->txtTitle_Create();
			$this->txtCategoryId1 = $this->mctProject->txtCategoryId1_Create();
			$this->txtCategoryId2 = $this->mctProject->txtCategoryId2_Create();
			$this->txtCategoryId3 = $this->mctProject->txtCategoryId3_Create();
			$this->txtCategoryId4 = $this->mctProject->txtCategoryId4_Create();
			$this->txtCategoryId5 = $this->mctProject->txtCategoryId5_Create();
			$this->txtCategory = $this->mctProject->txtCategory_Create();
			$this->txtDescription = $this->mctProject->txtDescription_Create();
			$this->txtOs = $this->mctProject->txtOs_Create();
			$this->txtDb = $this->mctProject->txtDb_Create();
			$this->txtBudgetMin = $this->mctProject->txtBudgetMin_Create();
			$this->txtBudgetMax = $this->mctProject->txtBudgetMax_Create();
			$this->txtFeatured = $this->mctProject->txtFeatured_Create();
			$this->txtHideBid = $this->mctProject->txtHideBid_Create();
			$this->txtHideSearch = $this->mctProject->txtHideSearch_Create();
			$this->txtGoldOnly = $this->mctProject->txtGoldOnly_Create();
			$this->txtEnable = $this->mctProject->txtEnable_Create();
			$this->txtSendmail = $this->mctProject->txtSendmail_Create();
			$this->txtTotalBid = $this->mctProject->txtTotalBid_Create();
			$this->calTimeLimitDate = $this->mctProject->calTimeLimitDate_Create();
			$this->calPostDate = $this->mctProject->calPostDate_Create();
			$this->calCancelDate = $this->mctProject->calCancelDate_Create();
			$this->calCloseDate = $this->mctProject->calCloseDate_Create();
			$this->calEndDate = $this->mctProject->calEndDate_Create();
			$this->txtStatus = $this->mctProject->txtStatus_Create();
			$this->txtWonUserId = $this->mctProject->txtWonUserId_Create();
			$this->txtAverageBid = $this->mctProject->txtAverageBid_Create();
			$this->calWonDate = $this->mctProject->calWonDate_Create();
			$this->calStartDate = $this->mctProject->calStartDate_Create();
			$this->calLastBidDate = $this->mctProject->calLastBidDate_Create();
			$this->lstProjectTypeObject = $this->mctProject->lstProjectTypeObject_Create();
			$this->lstBudgetTypeObject = $this->mctProject->lstBudgetTypeObject_Create();
			$this->lstTotalProjectdayTypeObject = $this->mctProject->lstTotalProjectdayTypeObject_Create();
			$this->chkHideSearchEngine = $this->mctProject->chkHideSearchEngine_Create();
			$this->chkAgreementCheck = $this->mctProject->chkAgreementCheck_Create();

			// Create Buttons and Actions on this Form
			$this->btnSave = new QButton($this);
			$this->btnSave->Text = QApplication::Translate('Save');
			$this->btnSave->AddAction(new QClickEvent(), new QAjaxAction('btnSave_Click'));
			$this->btnSave->CausesValidation = true;

			$this->btnCancel = new QButton($this);
			$this->btnCancel->Text = QApplication::Translate('Cancel');
			$this->btnCancel->AddAction(new QClickEvent(), new QAjaxAction('btnCancel_Click'));

			$this->btnDelete = new QButton($this);
			$this->btnDelete->Text = QApplication::Translate('Delete');
			$this->btnDelete->AddAction(new QClickEvent(), new QConfirmAction(QApplication::Translate('Are you SURE you want to DELETE this') . ' ' . QApplication::Translate('Project') . '?'));
			$this->btnDelete->AddAction(new QClickEvent(), new QAjaxAction('btnDelete_Click'));
			$this->btnDelete->Visible = $this->mctProject->EditMode;
		}
		
		protected function btnButton_Click($strFormId, $strControlId, $strParameter) {
			$this->lblMessage->Text = 'Your File Has been Uploaded ' . $this->ProjectFile->FileName;
			$_SESSION['newProject']['FileName']=$this->ProjectFile->FileName;
		}
		protected function InputSubcategory_Change($strFormId,$strControlId,$strParameter)
	{
		$intcategory=$this->lstCategory->SelectedValue;
		if (is_null($intcategory)) {
			$objectSubcategoryArray=Subcategory::LoadAll(QQ::Clause(QQ::OrderBy(QQN::Subcategory()->Type)));
			$this->lstSubcategory->Visible=true;
		}else {
			$objectSubcategoryArray=Subcategory::LoadArrayByCategoryId($intcategory,QQ::Clause(QQ::OrderBy(QQN::Subcategory()->Type)));
			$this->lstSubcategory->Visible=true;
		}
		$this->lstSubcategory->RemoveAllItems();
	
		foreach ($objectSubcategoryArray as $objSubcategory) {
			$this->lstSubcategory->AddItem(new QListItem($objSubcategory->Type,$objSubcategory->Id));
		}
	}

		/**
		 * This Form_Validate event handler allows you to specify any custom Form Validation rules.
		 * It will also Blink() on all invalid controls, as well as Focus() on the top-most invalid control.
		 */
		protected function Form_Validate() {
			// By default, we report that Custom Validations passed
			$blnToReturn = true;

			// Custom Validation Rules
			// TODO: Be sure to set $blnToReturn to false if any custom validation fails!

			$blnFocused = false;
			foreach ($this->GetErrorControls() as $objControl) {
				// Set Focus to the top-most invalid control
				if (!$blnFocused) {
					$objControl->Focus();
					$blnFocused = true;
				}

				// Blink on ALL invalid controls
				$objControl->Blink();
			}

			return $blnToReturn;
		}

		// Button Event Handlers

		protected function btnSave_Click($strFormId, $strControlId, $strParameter) {
			// Delegate "Save" processing to the ProjectMetaControl
			$this->mctProject->SaveProject();
			$this->RedirectToListPage();
		}

		protected function btnDelete_Click($strFormId, $strControlId, $strParameter) {
			// Delegate "Delete" processing to the ProjectMetaControl
			$this->mctProject->DeleteProject();
			$this->RedirectToListPage();
		}

		protected function btnCancel_Click($strFormId, $strControlId, $strParameter) {
			$this->RedirectToListPage();
		}

		// Other Methods

		protected function RedirectToListPage() {
			QApplication::Redirect(__SUBDIRECTORY__. '/Posting/newProject2.php');
		}
	}

	// Go ahead and run this form object to render the page and its event handlers, implicitly using
	// project_edit.tpl.php as the included HTML template file
	ProjectEditForm::Run('ProjectEditForm');
?>